﻿using System.Data;
using System.Data.SqlClient;
using NUnit.Framework;
using Pantry.Business;
using Pantry.Entity;
using Pantry.DataAccess;
using System.Transactions;
namespace Pantry.UnitTest
{
    [TestFixture]
    public class TestOrganisationDao
    {
        private const string ConnectionString = @"Server=10.16.102.126;Database=Pantry_MockProject;Integrated Security=True;";
        private Organisations _organisations;
        private OrganisationDao _organisationDao;
        private OrganisationBus _organisationBus;
        private TransactionScope _scope;
        [SetUp]
        public void  Init()
        {
            _scope = new TransactionScope();
            _organisationDao = new OrganisationDao(ConnectionString);
            _organisationBus = new OrganisationBus();
            _organisations = new Organisations()
                                 {
                                     Id = 1,
                                     Name = "Organisation Name 1",
                                     ShortDescription = "Descriptionaaaaaa",
                                     ContactId = 2,
                                     Address1 = "No 1 Cau Dien",
                                     Address2 = "92 Hang Ma",
                                     Address3 = "117 Ho Xuan Huong",
                                     City = "Thanh Xuan",
                                     County = "Hải Phòng",
                                     Country = "5",
                                     PreferredOrg = true,
                                     ExpOfInterest = true,
                                     TypeOfBusinessId = 1,
                                     FullDescription = "fdasoi",
                                     PhoneNumber = "999-999-9999",
                                     Fax = "999-999-9999",
                                     Email = "hellochao@mail.com",
                                     WebAddr = "http://web.vn",
                                     CharityNumber = "ffef",
                                     CompanyNumber = "fesaf",
                                     PostCode = "21",
                                     IsActive = true
                                     
                                 };


        }
        [TearDown]
        public void TearDown()
        {
            _scope.Dispose();
        }

        /// <summary>
        /// Tests the insert organisation_ valid value_ return true.
        /// </summary>
        [Test] 
        public void TestInsertOrganisation_ValidValue_ReturnTrue()
        {
            const bool expected = true;
            var actual = _organisationDao.Insert(_organisations);
            Assert.AreEqual(expected, actual);
        }
        /// <summary>
        /// Tests all organisation list_ return not null.
        /// </summary>
        [Test]
        public void TestAllOrganisationList_ReturnNotNull()
        {
            
            var actual = _organisationDao.SelectAllOrganisation();
            Assert.IsTrue(actual.Rows.Count >0);
        }
        /// <summary>
        /// Tests the insert organisation_ null directorate_ false.
        /// </summary>
        [Test]
        public void TestInsertOrganisation_NullDirectorate_False()
        {
            var organisation = new Organisations();
            const bool expected = false;
            var actual = _organisationDao.Insert(organisation);
            Assert.AreEqual(expected, actual);
        }
        /// <summary>
        /// Tests the insert organisation_ invalid name_ false.
        /// </summary>
        [Test]
        public void TestInsertOrganisation_InvalidName_False()
        {
            const bool expected = false;
            var organisationsNotvalid = new Organisations()
            {
                Id = 1,
                Name = "",
                ShortDescription = "Descriptionaaaaaa",
                ContactId = 2,
                Address1 = "No 1 Cau Dien",
                Address2 = "92 Hang Ma",
                Address3 = "117 Ho Xuan Huong",
                City = "Thanh Xuan",
                County = "Hải Phòng",
                Country = "5",
                PreferredOrg = true,
                ExpOfInterest = true,
                TypeOfBusinessId = 1,
                FullDescription = "fdasoi",
                PhoneNumber = "999-999-9999",
                Fax = "999-999-9999",
                Email = "hellochao@mail.com",
                WebAddr = "http://web.vn",
                CharityNumber = "ffef",
                CompanyNumber = "fesaf",
                PostCode = "21",
                IsActive = true

            };
            var actual = _organisationDao.Insert(organisationsNotvalid);
            Assert.AreEqual(expected, actual);
        }
        /// <summary>
        /// Tests the return organisation by id_ return true.
        /// </summary>
        [Test]
        public void TestReturnOrganisationById_ReturnTrue()
        {
            
            var actual = _organisationDao.ReturnOrganisationById(1);
            Assert.AreEqual(_organisations,actual);
        }
        /// <summary>
        /// Tests the update organisation_ valid input_ return true.
        /// </summary>
        [Test]
        public void TestUpdateOrganisation_ValidInput_ReturnTrue()
        {
            const bool expected = true;
            var organisation = new Organisations()
            {
                Id = 1,
                Name = "Name Edit",
                ShortDescription = "Descriptionaaaaaa",
                ContactId = 2,
                Address1 = "No 1 Cau Dien",
                Address2 = "92 Hang Ma",
                Address3 = "117 Ho Xuan Huong",
                City = "Thanh Xuan",
                County = "Hải Phòng",
                Country = "5",
                PreferredOrg = true,
                ExpOfInterest = true,
                TypeOfBusinessId = 1,
                FullDescription = "fdasoi",
                PhoneNumber = "999-999-9999",
                Fax = "999-999-9999",
                Email = "hellochao@mail.com",
                WebAddr = "http://web.vn",
                CharityNumber = "ffef",
                CompanyNumber = "fesaf",
                PostCode = "21",
                IsActive = true

            };
            var actual = _organisationDao.Edit(organisation);
            Assert.AreEqual(expected,actual);
        }
        /// <summary>
        /// Tests the check organisation name exists_ return true.
        /// </summary>
        [Test]
        public void TestCheckOrganisationNameExists_ReturnTrue()
        {
            const bool expected = true;
            var actual = _organisationDao.CheckOrganisationNameExists("Creat new");
            Assert.AreEqual(expected, actual);
        }
        /// <summary>
        /// Tests the mark activated_ return true.
        /// </summary>
        [Test]
        public void TestMarkActivated_ReturnTrue()
        {
            const bool expected = true;
            var actual = _organisationDao.MarkActivated(false,1);
            Assert.AreEqual(expected, actual);
        }
    }
}
